package quoc.phu;

import adapter.SubjectAdapter;
import adapter.SubjectList;
import android.os.Bundle;
import android.app.Activity;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;

public class od_SubjectActivity extends Activity {
	public static String 
	ExpandableListView expSubject;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.od_activity_subject);
        expSubject=(ExpandableListView)findViewById(R.id.expSubject);
        
       
        SubjectList subjects = new SubjectList();
		subjects.init(SubjectList.test);
		 ExpandableListAdapter adapter = new SubjectAdapter(this, subjects);
		expSubject.setAdapter(adapter);
		registerForContextMenu(expSubject);
    }

    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {

    	super.onCreateContextMenu(menu, v, menuInfo);
    	ExpandableListView.ExpandableListContextMenuInfo info =    	(ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    	int type =    	ExpandableListView.getPackedPositionType(info.packedPosition);
    	int group =    	ExpandableListView.getPackedPositionGroup(info.packedPosition);
    	int child =    	ExpandableListView.getPackedPositionChild(info.packedPosition);
    	if(type==1){
			menu.add(0, 1, 0, "Xem thông tin");
			menu.add(0, 2, 0, "Xem chi tiết");			
    	}else{
    		menu.add(0,3,0,"Thêm chủ đề");
    	}
	}

	public boolean onContextItemSelected(MenuItem menuItem) {
		ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
		int groupPos = 0, childPos = 0;
		int type = ExpandableListView.getPackedPositionType(info.packedPosition);
		if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
			groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
			childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
		}
		return super.onContextItemSelected(menuItem);

	}

    
}
